<template> 
    <mdp-lr-box :lspan="12">
        <template #left> 
            
            <mdp-meta-option :item="{id:'projectType',itemCode:'projectType',itemName:'项目类型'}" simple @row-click="onRowClick">
                <template #title>
                    <el-alert type="warning" :closable="false">项目类型</el-alert>
                </template>
            </mdp-meta-option>
        </template>  
            
            <div class="padding-left">
                
                <ContentWrap v-if="metaOption?.id && !projectPhasePlansItem?.id"> 
                    <template #header>
                        <el-space wrap >  
                             <div v-if="!projectPhasePlansItem?.id">字典【{{metaOption?.name}}】不存在，是否创建？<el-button type="primary" @click="createDict">创建</el-button></div>
                         </el-space>  
                    </template>
                </ContentWrap>

                <mdp-meta-option v-if="projectPhasePlansItem?.id" :item="projectPhasePlansItem" simple>
                    
                    <template #title>
                        <el-alert type="warning" :closable="false">项目管理节点（自动创建项目计划一级目录）</el-alert> 
                    </template>
                </mdp-meta-option>

            </div>
    </mdp-lr-box>
</template>

<script>  
import { mapState } from 'pinia'
import { useUserStore } from '@/store/modules/user'

export default {
    name:'ProjectTypeCfg', 
    computed: {
        ...mapState(useUserStore,['userInfo'])
    },
    props:{
       
    },
    data() {
        return {
            load:{list:false},
             metaOption:null, 
             projectPhasePlansItem:null,
        }
    },
    methods: {
          onRowClick(row){
            this.metaOption=null
            this.metaOption=row
            var item={itemCode:'projectPhasePlans'+row.id,categoryId:'all'};
            this.$mdp.listItem(item).then(res=>{
                var tips = res.tips
                if(tips.isOk && res.data.length>0){
                    this.projectPhasePlansItem=res.data[0]
                }else{
                    this.projectPhasePlansItem=null
                }
            })
          },
          createDict(){
            var row=this.metaOption
            var item={id:'projectPhasePlans'+row.id, itemCode:'projectPhasePlans'+row.id,categoryId:'all',name:row.name};
            this.$mdp.addItem(item).then(res=>{
                var tips = res.tips
                if(tips.isOk){
                    this.$notify.success("创建字典成功")
                    this.projectPhasePlansItem=res.data
                }else{
                    this.$notify.error(tips.msg)
                }
            })
          },
           
    },
    mounted() {

    }
}

</script>

<style scoped>

</style>